package com.sense.kukoo.biz_media.adapter

import android.view.View
import com.sense.kukoo.biz_media.adapter.provider.*
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.repo.bean.MediaListDetailItemBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class MediaListDetailAdapter(
    val listener: MediaListListener,
    data: MutableList<MediaListDetailItemBean>
) : MultiItemAdapter<MediaListDetailItemBean>(data) {

    private val TAG: String = javaClass.simpleName

    val mediaTitleProvider = MediaTitleProvider(listener)
    val mediaListItemProvider = AudiobookItemProvider(listener)
    val podcastItemProvider = PodcastItemProvider(listener)
    val shortAudioItemProvider = ShortAudioItemProvider(listener)

    init {
        addItemProvider(mediaTitleProvider)
        addItemProvider(mediaListItemProvider)
        addItemProvider(podcastItemProvider)
        addItemProvider(shortAudioItemProvider)
    }

    override fun getItemType(data: MutableList<MediaListDetailItemBean>, position: Int): Int {
        return data.get(position).type
    }

    interface MediaListListener {
        fun onBtnListenClick(bean: MediaListDetailItemBean)
        fun onBtnQuestionClick(question: View)
        fun onBtnSubscribeClick(bean: MediaListDetailItemBean)
        fun onBtnSortClick(bean: MediaListDetailItemBean)
        fun onBtnMediaItemClick(bean: MediaListDetailItemBean)
        fun onBtnPodcastItemClick(bean: MediaListDetailItemBean)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mediaTitleProvider.setCurrentMusic(music)
        mediaListItemProvider.setCurrentMusic(music)
        podcastItemProvider.setCurrentMusic(music)
        shortAudioItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mediaTitleProvider.setCurrentPlayState(state)
        mediaListItemProvider.setCurrentPlayState(state)
        podcastItemProvider.setCurrentPlayState(state)
        shortAudioItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }
}